/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InfosVIP.java
 *
 * Created on 16 juin 2011, 11:53:32
 */

package cannes.gui;

import cannes.bean.planning.Personne;
import cannes.bean.vip.Vip;
import cannes.dao.DAO;
import cannes.dao.DAOFactory;

/**
 *
 * @author p1008977
 */
public class InfosVIP extends javax.swing.JPanel {

    /** Creates new form InfosVIP */
    public InfosVIP(Vip vip) {
        initComponents();
        this.vip = vip;
        initValeur(vip);
        id = vip.getId();
    }

    private void initValeur(Vip vip)
    {
        nom.setText(vip.getNom());
        prenom.setText(vip.getPrenom());
        nationalite.setText(vip.getNationalite());
        type.setText(vip.getType());
        attrait.setText(String.valueOf(vip.getAttrait()));
        nom.setEditable(false);
        prenom.setEditable(false);
        nationalite.setEditable(false);
        type.setEditable(false);
        attrait.setEditable(false);
        creat.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        nom = new javax.swing.JTextField();
        prenom = new javax.swing.JTextField();
        nationalite = new javax.swing.JTextField();
        photo = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        type = new javax.swing.JTextField();
        attrait = new javax.swing.JTextField();
        ok = new javax.swing.JButton();
        modif = new javax.swing.JButton();
        apply = new javax.swing.JButton();
        creat = new javax.swing.JButton();

        jLabel1.setText("Nom");

        jLabel2.setText("Prenom");

        jLabel3.setText("Nationalite");

        jLabel4.setText("Photo");

        photo.setEditable(false);
        photo.setText("Null");

        jLabel5.setText("Type");

        jLabel6.setText("Attrait");

        ok.setText("OK");

        modif.setText("Modifier");
        modif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modifActionPerformed(evt);
            }
        });

        apply.setText("Appliquer");
        apply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyActionPerformed(evt);
            }
        });

        creat.setText("Creer un VIP");
        creat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                creatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(nationalite, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(prenom, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(nom, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
                    .addComponent(attrait, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                    .addComponent(type, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                    .addComponent(photo, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(creat, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(apply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(modif, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(ok, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(prenom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(nationalite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(creat))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(photo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(modif))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(apply))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(attrait, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ok))
                .addContainerGap(64, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void modifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modifActionPerformed
        nom.setEditable(true);
        prenom.setEditable(true);
        nationalite.setEditable(true);
        type.setEditable(true);
        attrait.setEditable(true);
    }//GEN-LAST:event_modifActionPerformed

    private void applyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyActionPerformed
        vipDAO = DAOFactory.getVipDAO();
//        Vip v = vipDAO.find(id);
        //vip = new Vip(vip.getId(), vip.getCompagnonId(), type.getText(), Integer.parseInt(attrait.getText()), nom.getText(), prenom.getText(),photo.getText(), nationalite.getText());
//        v.setType(type.getText());
//        v.setAttrait(Integer.parseInt(attrait.getText()));
//        v.setNom(nom.getText());
//        v.setPrenom(prenom.getText());
//        v.setPhoto(null);
//        v.setNationalite(nationalite.getText());
        vip.setType(type.getText());
        vip.setAttrait(Integer.parseInt(attrait.getText()));
        vip.setNom(nom.getText());
        vip.setPrenom(prenom.getText());
        vip.setPhoto(null);
        vip.setNationalite(nationalite.getText());
        vipDAO.update(vip);
    }//GEN-LAST:event_applyActionPerformed

    private void creatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_creatActionPerformed
        vipDAO = DAOFactory.getVipDAO();
        personneDAO = DAOFactory.getPersonneDAO();
        Vip v = new Vip();
        v.setId(personneDAO.next());
        v.setType(type.getText());
        v.setAttrait(Integer.parseInt(attrait.getText()));
        v.setNom(nom.getText());
        v.setPrenom(prenom.getText());
        v.setPhoto(null);
        v.setNationalite(nationalite.getText());
        // Vip vip = new Vip(personneDAO.next(), 11, type.getText(),Integer.parseInt(attrait.getText()), nom.getText(), prenom.getText(),photo.getText(), nationalite.getText() );
        vipDAO.create(v);
    }//GEN-LAST:event_creatActionPerformed

    public void nouveau() {
        modif.setEnabled(false);
        apply.setEnabled(false);
        creat.setEnabled(true);
        nom.setEditable(true);
        prenom.setEditable(true);
        nationalite.setEditable(true);
        type.setEditable(true);
        attrait.setEditable(true);
    }

    public void modif() {
        modif.setEnabled(false);
        apply.setEnabled(true);
        creat.setEnabled(false);
        nom.setEditable(true);
        prenom.setEditable(true);
        nationalite.setEditable(true);
        type.setEditable(true);
        attrait.setEditable(true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton apply;
    private javax.swing.JTextField attrait;
    private javax.swing.JButton creat;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JButton modif;
    private javax.swing.JTextField nationalite;
    private javax.swing.JTextField nom;
    private javax.swing.JButton ok;
    private javax.swing.JTextField photo;
    private javax.swing.JTextField prenom;
    private javax.swing.JTextField type;
    // End of variables declaration//GEN-END:variables
    DAO<Vip> vipDAO;
    DAO<Personne> personneDAO;
    int id;
    Vip vip;
}
